import java.util.ArrayList;
import java.util.HashMap;

import scheduler.Scheduler;
import utils.Granularidade;
import utils.Utils;

import model.Entidade;
import model.LockInfo;
import model.Operacao;


public class Main {
	
	public static void main(String[] args) {
		HashMap<String, Entidade> database = Utils.initializeDBtoMap();
		Utils.printMapDB(database);
		ArrayList<LockInfo> lista = new ArrayList<LockInfo>();
//		LockInfo l1 = new LockInfo(1, 2, 1, LockInfo.WL, LockInfo.GRANTED);
//		lista.add(l1);
//		lista.add(new LockInfo(2, 1, 1, LockInfo.WL, LockInfo.WAITING));
//		lista.add(new LockInfo(2, 3, 1, LockInfo.WL, LockInfo.WAITING));
//		lista.add(new LockInfo(3, 4, 20, LockInfo.WL, LockInfo.GRANTED));
//		lista.add(new LockInfo(4, 5, 1, LockInfo.WL, LockInfo.WAITING));
//		lista.add(new LockInfo(5, 4, 1, LockInfo.WL, LockInfo.WAITING));
		lista.add(new LockInfo(1, 2, "tab1", LockInfo.WL, LockInfo.GRANTED));
		lista.add(new LockInfo(2, 1, "tab1", LockInfo.WL, LockInfo.WAITING));
		lista.add(new LockInfo(1, 4, "tab1", LockInfo.WL, LockInfo.WAITING));
		lista.add(new LockInfo(4, 5, "tab1", LockInfo.WL, LockInfo.WAITING));
		lista.add(new LockInfo(5, 4, "tab1", LockInfo.WL, LockInfo.WAITING));
		boolean b = LockInfo.deadLockCheck(lista);
//		System.out.println("DeadLock? "+b);
		Granularidade.initialize();
		Granularidade.imprimeTabela();
		
		/////////////////////CODIGO PRA VALER!!!!----------------------------------------
//		String schedule = "r 1 tab11| w 2 tab11";
		// r1(y)r2(u)r2(x)w3(u)r3(v)c3w1(v)c2c1; 
		String schedule = "R 1 Y|R 2 U|R 2 X|W 3 U|R 3 V|C 3|W 1 V|C 2|C 1";
		ArrayList<Operacao> escalonados = Scheduler.start(schedule);
		Scheduler.printSchedule(escalonados);
	}


}